define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'giy/order/index' + location.search,
                    add_url: 'giy/order/add',
                    edit_url: 'giy/order/edit',
                    del_url: 'giy/order/del',
                    multi_url: 'giy/order/multi',
                    import_url: 'giy/order/import',
                    table: 'giy_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'order_id',
                sortName: 'order_id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'order_sn', title: __('Order_sn'), operate: 'LIKE'},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'goods_id', title: __('Goods_id')},
                        {field: 'quantity', title: __('Quantity')},
                        {field: 'total_amount', title: __('Total_amount'), operate:'BETWEEN'},
                        {field: 'address_id', title: __('Address_id')},
                        {field: 'pay_type', title: __('Pay_type'), searchList: {"1":__('Pay_type 1'),"2":__('Pay_type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'goods_type', title: __('Goods_type'), searchList: {"1":__('Goods_type 1'),"2":__('Goods_type 2'),"3":__('Goods_type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'order_status', title: __('Order_status'), searchList: {"1":__('Order_status 1'),"2":__('Order_status 2'),"3":__('Order_status 3'),"5":__('Order_status 5'),"6":__('Order_status 6')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'goods.name', title: __('Goods.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'goods.goods_image', title: __('Goods.goods_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'address.recipient_name', title: __('Address.recipient_name'), operate: 'LIKE'},
                        {field: 'address.phone_number', title: __('Address.phone_number'), operate: 'LIKE'},
                        {field: 'address.address_line', title: __('Address.address_line'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'address.area', title: __('Address.area'), operate: 'LIKE'},
                        {field: 'address.city', title: __('Address.city'), operate: 'LIKE'},
                        {field: 'address.province', title: __('Address.province'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
